package com.fsc.comadapoc1.presentation.panels
{
	import com.fsc.comadapoc1.domain.PortfolioModel;
	import com.fsc.comadapoc1.events.LoadPortfolioEvent;
	import com.fsc.comadapoc1.events.LoadPortfolioFundsEvent;
	import com.fsc.comadapoc1.events.PanelChangeEvent;
	
	import flash.events.EventDispatcher;

	[Event(name="changeState", type="events.PanelChangeEvent")]
	[Event(name="loadPortfolioFunds", type="events.LoadPortfolioFundsEvent")]
	[ManagedEvents(names="loadPortfolioFunds,changeState")]
	public class PortfolioPanelPM extends EventDispatcher
	{
		
		[Inject]
		[Bindable]
		public var model:PortfolioModel;
		
		/** The landing state **/
		public const LANDING_STATE : String = "landingState";
		
		/** The searching state. **/
		public const SEARCHING_STATE : String = "searchingState";
		
		/** The results state. **/
		public const RESULTS_STATE : String = "resultsState";
		
		/** The no results state. **/
		public const NO_RESULTS_STATE : String = "noResultsState";
		
		public function back():void{
			dispatchEvent(new PanelChangeEvent(PanelChangeEvent.PORTFOLIOS_VIEW_STATE));
			model.currentPortfolio.pendingTradesPage = 1;
		}
		
		public function subscribe():void{
			dispatchEvent(new PanelChangeEvent(PanelChangeEvent.SUBSCRIPTIONS_VIEW_STATE));
			dispatchEvent(new LoadPortfolioFundsEvent(LoadPortfolioFundsEvent.LOAD_PORTFOLIO_FUNDS,""));
		}
		
	
		
		private var _currentState:String = LANDING_STATE;
		
		/**
		 * Get the current state of the presentation model.
		 */
		[Bindable]
		public function get currentState() : String
		{
			return _currentState;
		}
		
		/**
		 * Sets the current state of the presentation model.
		 */
		public function set currentState( state:String ) : void
		{
			_currentState = state;	
		}
		
		[MessageHandler(selector="portfoliosViewState")]
		public function handleStateChange(event:PanelChangeEvent):void{
		
		}
	}
}